/**
 * 预约建档初始化
 */
var ReservationsRecordTable = {
    id: "ReservationsRecordTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
ReservationsRecordTable.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {
            title: '预约号', field: 'reservationsNum', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        {
            title: '标识号', field: 'identificationNumber', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        {
            title: '客户姓名', field: 'customerName', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    if (row.oneChannel == "直接上门") {
                        return "<a href='javascript:;'onclick = 'ReservationsRecordTable.reservationsArrive(" + '"' + row.id + '"' + ")' > <span style='color: green'>" + value + "</span></a>"
                    } else if (row.department == "电销咨询" || row.department == "公共池") {
                        return "<a href='javascript:;' onclick='ReservationsRecordTable.reservationsArrivess(" + '"' + row.id + '"' + ")'> <span style='color: green'>" + value + "</span></a>"
                    } else {
                        return "<a href='javascript:;'onclick = 'ReservationsRecordTable.reservationsArrives(" + '"' + row.id + '"' + ")' > <span style='color: green'>" + value + "</span></a>"
                    }
                } else {
                    if (row.oneChannel == "直接上门") {
                        return "<a href='javascript:;'onclick = 'ReservationsRecordTable.reservationsArrive(" + '"' + row.id + '"' + ")' > " + value + " </a>"
                    } else if (row.department == "电销咨询" || row.department == "公共池") {
                        return "<a href='javascript:;' onclick='ReservationsRecordTable.reservationsArrivess(" + '"' + row.id + '"' + ")'>" + value + " </a>"
                    } else {
                        return "<a href='javascript:;'onclick = 'ReservationsRecordTable.reservationsArrives(" + '"' + row.id + '"' + ")' > " + value + " </a>"
                    }
                }
            },
        },
        {
            title: '手机号码', field: 'customerPhone', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        // {title: '到店状态', field: 'status', align: 'center', valign: 'middle',  sortable: true,},
        {
            title: '初诊门诊', field: 'arrivalStore', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value.substring(0, 19);
                }
            }
        },
        {
            title: '建档人', field: 'archiving', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        {
            title: '跟进人', field: 'follower', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        {
            title: '归属人', field: 'belonger', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        {
            title: '部门', field: 'department', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        {
            title: '建档时间', field: 'filingTime', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value.substring(0, 19) + "</span>"
                } else {
                    return value.substring(0, 19);
                }
            }
        },
        {
            title: '预约时间', field: 'appointmentTime', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.huifang == "" || row.huifang == null) {
                    row.huifang = "无回访详情";
                } else {
                    var reg = /,/g;
                    row.huifang = row.huifang.replace(reg, '');
                }
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green; cursor:pointer' title='" + row.huifang + "' >" + value.substring(0, 19) + "</span>"
                } else {
                    return "<span style=' cursor:pointer' title='" + row.huifang + "' >" + value.substring(0, 19) + "</span>"
                }
            }
        },
        {
            title: '到诊时间', field: 'firstVisitDate', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value.substring(0, 19) + "</span>"
                } else {
                    return value.substring(0, 19);
                }
            }
        },
        {title: '回访', field: 'huifang', visible: false, align: 'center', valign: 'middle', sortable: true, width: 120},
        {
            title: '一级渠道', field: 'oneChannel', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value.substring(0, 19);
                }
            }
        },
        {
            title: '二级渠道',
            visible: false,
            field: 'twoChannel',
            align: 'center',
            valign: 'middle',
            sortable: true,
            width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value.substring(0, 19);
                }
            }
        },
        {
            title: '三级渠道',
            visible: false,
            field: 'thrChannel',
            align: 'center',
            valign: 'middle',
            sortable: true,
            width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value.substring(0, 19);
                }
            }
        },
        {
            title: '性别', field: 'customerSex', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                var sexValue = "";
                if (value == 1) {
                    sexValue = "男";
                } else if (value == 2) {
                    sexValue = "女"
                } else {
                    sexValue = "未知"
                }
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + sexValue + "</span>"
                } else {
                    return sexValue;
                }
            }
        },
        {
            title: '年龄', field: 'customerAge', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        {
            title: '成交状态',
            visible: false,
            field: 'dealStatus',
            align: 'center',
            valign: 'middle',
            sortable: true,
            width: 120,
            formatter: function (value, row, index) {
                if (value == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        {
            title: '成交金额', field: 'money', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (value == null || value == "") {
                    if (row.dealStatus == "已成交") {
                        return "<span style='color: green'>0.00</span>"
                    } else {
                        return "0.00";
                    }
                } else {
                    if (row.dealStatus == "已成交") {
                        return "<span style='color: green'>" + value + "</span>"
                    } else {
                        return "0.00";
                    }
                }
            }
        },
        {
            title: '预约病种',
            field: 'appointmentPayService',
            align: 'center',
            valign: 'middle',
            sortable: true,
            width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value.substring(0, 19);
                }
            }
        },
        {
            title: '访问病种', field: 'accessDisease', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value.substring(0, 19);
                }
            }
        },
        {
            title: '消费项目', field: 'expenditureProject', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value.substring(0, 19);
                }
            }
        },
        {
            title: '初诊TC', field: 'tcName', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value.substring(0, 19);
                }
            }
        },
        {
            title: '关键词', field: 'keyWord', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value.substring(0, 19);
                }
            }
        },
        {
            title: '微信号', field: 'wechatNumber', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (row.dealStatus == "已成交") {
                    return "<span style='color: green'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
    ]
    return columns;
}
;

/**
 * 查询预约客户列表
 */
ReservationsRecordTable.search = function () {
    // ReservationsRecordTable.moneyAccount();
    ReservationsRecordTable.table.refresh({query: ReservationsRecordTable.formParams()});
    ReservationsRecordTable.tongji();
}

ReservationsRecordTable.getData = function () {
    ReservationsRecordTable.search();
}

ReservationsRecordTable.suspensionOut = function () {
    $('#suspension_box').remove();
};

ReservationsRecordTable.getFollower = function () {
    var index = layer.open({
        type: 2,
        title: '添加跟进人',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/to_follower'
    });
    this.layerIndex = index;
};

ReservationsRecordTable.getBelonger = function () {
    var index = layer.open({
        type: 2,
        title: '添加跟进人',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/to_belonger'
    });
    this.layerIndex = index;
};

ReservationsRecordTable.reservationsNotDetails = function (id) {
    var pageType = $("#pageType").val();
    window.localStorage.setItem("c", pageType);
    var index = layer.open({
        type: 2,
        title: '预约客户详情',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservationsNotArrive/to_reservationsNotDetails/' + id
    });
    this.layerIndex = index;
};

ReservationsRecordTable.suspensionOver = function (id) {
    var str = "";
    var evt = evt || window.event;
    $('#suspension_box').remove();
    var oDiv = document.createElement('div');
    $.ajax({
        url: Feng.ctxPath + "/reservations/getHuiFang",
        type: "post",
        data: {
            "id": id
        },
        success: function (data) {
            if (data) {
                var data_sp = data.substring(1, data.length - 1);
                var arr = data_sp.split('\\n');
                arr.forEach(function (v) {
                    str += "<p>" + v + "</p>"
                });
            } else {
                str = '';
            }
            oDiv.id = 'suspension_box';
            oDiv.innerHTML = str;
            var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
            var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
            var x = evt.pageX || evt.clientX + scrollX;
            var y = evt.pageY || evt.clientY + scrollY;

            oDiv.style.left = x + 0 + 'px';  // 指定创建的DIV在文档中距离左侧的位置
            oDiv.style.top = y + 20 + 'px';  // 指定创建的DIV在文档中距离顶部的位置
            oDiv.style.position = 'absolute'; // 为新创建的DIV指定绝对定位
            oDiv.style.padding = "10px";
            oDiv.style.fontSize = "16px";
            oDiv.style.backgroundColor = ' #75B4ED';
            oDiv.style.color = 'white';
            document.body.appendChild(oDiv);
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
};


/**
 * 到店客户详情
 */
ReservationsRecordTable.reservationsArrive = function (id) {
    var index = layer.open({
        type: 2,
        title: '预约客户详情',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservationsArrive/reservations_arrive/' + id
    });
    this.layerIndex = index;
};

ReservationsRecordTable.reservationsArrives = function (id) {
    var index = layer.open({
        type: 2,
        title: '预约客户详情',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservationsArrive/reservations_arrives/' + id
    });
    this.layerIndex = index;
};

ReservationsRecordTable.reservationsArrivess = function (id) {
    var index = layer.open({
        type: 2,
        title: '预约客户详情',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservationsArrive/reservations_arrivess/' + id
    });
    this.layerIndex = index;
};

ReservationsRecordTable.reservationsArrive = function (id) {
    var index = layer.open({
        type: 2,
        title: '预约客户详情',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservationsArrive/reservations_arrive/' + id
    });
    this.layerIndex = index;
};

ReservationsRecordTable.today = function () {
    document.getElementById("startFirstVisitDate").value = newDate + " " + "00:00:00";
    document.getElementById("endFirstVisitDate").value = newDate + " " + "23:59:59";
};

ReservationsRecordTable.yesteray = function () {
    document.getElementById("startFirstVisitDate").value = yestDate + " " + "00:00:00";
    document.getElementById("endFirstVisitDate").value = yestDate + " " + "23:59:59";
};

ReservationsRecordTable.thisMonth = function () {
    var lastDay = 28;
    if (Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 12) {
        lastDay = 31;
    }
    else if (Month == 4 || Month == 6 || Month == 9 || Month == 11) {
        lastDay = 30;
    }
    document.getElementById("startFirstVisitDate").value = newMonth + "-" + "01" + " " + "00:00:00";
    document.getElementById("endFirstVisitDate").value = newMonth + "-" + lastDay + " " + "23:59:59";

};

ReservationsRecordTable.lastMonth = function () {
    var lastDay = 28;
    if (Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 12) {
        lastDay = 31;
    }
    else if (Month == 4 || Month == 6 || Month == 9 || Month == 11) {
        lastDay = 30;
    }
    document.getElementById("startFirstVisitDate").value = lastMonth + "-" + "01" + " " + "00:00:00";
    document.getElementById("endFirstVisitDate").value = lastMonth + "-" + lastDay + " " + "23:59:59";

};


/**
 * 检查是否选中
 */
ReservationsRecordTable.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        ReservationsRecordTable.seItem = selected[0];
        return true;
    }
};
//把对象拼接成URL的键值对参数param1=value1&param2=value2
var parseParam = function (param) {
    var paramStr = "";

    $.each(param, function (i) {
        paramStr += '&' + getSingleData(param, i);
    });
    return paramStr.substr(1);
};

var getSingleData = function (param, key) {
    return key + "=" + param[key];
}

/**
 *  新 市场预约表单查询提交参数
 * @returns {{}}
 */
ReservationsRecordTable.formParams = function () {
    var queryData = {};
    queryData['arrivalStore'] = $("#arrivalStore").val(); //门诊
    queryData['department'] = $("#department").val(); //  部门
    queryData['reach'] = $("#reach").val().trim();  //姓名   电话   微信  预约号
    queryData['appointmentPayService'] = $("#appointmentPayService").val();  //预约项目
    queryData['archiving'] = $("#archiving").val();   //建档人
    queryData['follower'] = $("#follower").val();   //跟进人
    queryData['accessDisease'] = $("#accessDisease").val();  //访问病种
    queryData['oneChannel'] = $("#oneChannel").val();  //一级渠道
    queryData['twoChannel'] = $("#twoChannel").val();    //二级渠道
    queryData['thrChannel'] = $("#thrChannel").val();    //三级渠道
    queryData['wechatNumber'] = $("#wechatNumber").val();   //微信
    queryData['statuss'] = $("#statuss").val();   //状态
    queryData['belonger'] = $("#belonger").val();   //归属人
    queryData['status'] = $("#status").val();   //状态
    var pageType = $("#pageType").val();//空值表示是建档界面，0 未到界面  1已到界面
    if (pageType == '0') {
        //建档
        queryData['startFilingTime'] = $("#startFilingTime").val();  //建档时间
        queryData['endFilingTime'] = $("#endFilingTime").val();
    } else if (pageType == '1') {
        //已到
        queryData['startFirstVisitDate'] = $("#startFirstVisitDate").val();  //建档时间
        queryData['endFirstVisitDate'] = $("#endFirstVisitDate").val();
    } else if (pageType == '2') {
        //未到
        queryData['startAppointmentTime'] = $("#startAppointmentTime").val();  //建档时间
        queryData['endAppointmentTime'] = $("#endAppointmentTime").val();
    }
    queryData['pageType'] = $("#pageType").val();   // 界面参数
    //JSON.stringify() 输出对象的全部内容
    // alert(JSON.stringify(queryData));
    return queryData;
}

/**
 *  新建
 */
ReservationsRecordTable.addToReservations = function () {
    var index = layer.open({
        type: 2,
        title: '添加预约客户',
        area: ['60%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservation/reservations_addTo'
    });
    this.layerIndex = index;
};

/**
 *  选择建档人
 */
ReservationsRecordTable.getArchiving = function () {
    var index = layer.open({
        type: 2,
        title: '选中建档人',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservation/to_archiving'
    });
    this.layerIndex = index;
};

/**
 *  已到导出
 */
ReservationsRecordTable.reservationsExport = function () {
    var queryData = {};
    queryData['arrivalStore'] = $("#arrivalStore").val(); //门诊
    queryData['department'] = $("#department").val(); //  部门
    queryData['reach'] = $("#reach").val().trim();  //姓名   电话   微信  预约号
    queryData['appointmentPayService'] = $("#appointmentPayService").val();  //预约项目
    queryData['archiving'] = $("#archiving").val();   //建档人
    queryData['follower'] = $("#follower").val();   //跟进人
    queryData['accessDisease'] = $("#accessDisease").val();  //访问病种
    queryData['oneChannel'] = $("#oneChannel").val();  //一级渠道
    queryData['twoChannel'] = $("#twoChannel").val();    //二级渠道
    queryData['thrChannel'] = $("#thrChannel").val();    //三级渠道
    queryData['wechatNumber'] = $("#wechatNumber").val();   //微信
    queryData['statuss'] = $("#statuss").val();   //状态
    queryData['belonger'] = $("#belonger").val();   //归属人
    var pageType = $("#pageType").val();
    if (pageType == '0') {
        //建档
        queryData['status'] = $("#status").val();   //状态
        queryData['startFilingTime'] = $("#startFilingTime").val();  //建档时间
        queryData['endFilingTime'] = $("#endFilingTime").val();
    } else if (pageType == '1') {
        //已到
        queryData['startFirstVisitDate'] = $("#startFirstVisitDate").val();  //建档时间
        queryData['endFirstVisitDate'] = $("#endFirstVisitDate").val();
    } else if (pageType == '2') {
        //未到
        queryData['startAppointmentTime'] = $("#startAppointmentTime").val();  //建档时间
        queryData['endAppointmentTime'] = $("#endAppointmentTime").val();
    }
    queryData['pageType'] = $("#pageType").val();   // 界面参数
    var param = parseParam(queryData);
    location.href = Feng.ctxPath + '/reservation/reservationsExportYD?' + param;
}

/**
 * 重置
 */
ReservationsRecordTable.resetSearch = function () {
    $("#reach").val("");
    $("#archiving").val("");
    $("#follower").val("");
    $("#accessDisease").val("");
    $("#statuss").val("");
    $("#status").val("");
    $("#belonger").val("");
    var pageType = $("#pageType").val();//空值表示是建档界面，0 未到界面  1已到界面
    if (pageType == '0') {
        //建档
        $("#startFilingTime").val("");
        $("#endFilingTime").val("");
        // document.getElementById("startFilingTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
        // document.getElementById("endFilingTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    } else if (pageType == '1') {
        //已到
        $("#startFirstVisitDate").val("");
        $("#endFirstVisitDate").val("");
        // document.getElementById("startFirstVisitDate").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
        // document.getElementById("endFirstVisitDate").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    } else if (pageType == '2') {
        //未到
        $("#startAppointmentTime").val("");
        $("#endAppointmentTime").val("");
        // document.getElementById("startAppointmentTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
        // document.getElementById("endAppointmentTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    }

    $("#appointmentPayService").val("");
    $("#oneChannel").val("请选择");
    $("#twoChannel").val("请选择");
    $("#thrChannel").val("请选择");
    $("#arrivalStore").val("");
    $("#wechatNumber").val("");
    $("#department").val("");
    ReservationsRecordTable.search();
};


ReservationsRecordTable.moneyAccount = function () {
    //查询成交金额
    $.ajax({
        type: "GET",
        url: Feng.ctxPath + '/reservationsArrive/account',
        data: ReservationsRecordTable.formParams(),
        dataType: "json",
        success: function (data) {
            $('#recordMoney').html(data.totalMoney);
        }
    })
}
/**
 * 统计建档，已到，未到 人数
 */
ReservationsRecordTable.tongji = function () {
    //获取门诊、部门、建档人参数
    var param1 = $("#arrivalStore").val();  //门诊
    var param2 = $("#department").val();   //部门
    var param3 = $("#archiving").val();  //建档人
    var param4 = $("#thrChannel").val(); //三级渠道
    var param5 = $("#twoChannel").val();  //二级渠道
    var param6 = $("#oneChannel").val();  //一级渠道
    var param7 = $("#statuss").val();  //状态
    var param8 = $("#accessDisease").val();  //访问病种
    var param9 = $("#appointmentPayService").val();  //访问项目
    var param10 = $("#status").val();  //状态
    var param11 = $("#follower").val();  //状态
    var param12 = $("#belonger").val();  //状态
    //发送ajax请求后台查询统计信息，赋值到对应的地方
    $.ajax({
        type: "GET",
        url: Feng.ctxPath + "/reservation/tongji",
        data: {
            param1: param1, param2: param2, param3: param3,
            param4: param4, param5: param5, param6: param6,
            param7: param7, param8: param8, param9: param9,
            param10: param10, param11: param11, param12: param12
        },
        dataType: "json",
        success: function (data) {
            var pageType = $("#pageType").val();//空值表示是建档界面，0 未到界面  1已到界面
            if (pageType == '0') {
                //建档
                $("#dengjiToday").html(data[0].countNum);
                $("#dengjiYesterday").html(data[3].countNum);
                $("#dengjiMonth").html(data[6].countNum);
                $("#dengjiLastMonth").html(data[9].countNum);
            } else if (pageType == '1') {
                //已到
                $("#daozhenToday").html(data[1].countNum);
                $("#daozhenYesterday").html(data[4].countNum);
                $("#daozhenMonth").html(data[7].countNum);
                $("#daozhenLastMonth").html(data[10].countNum);
            } else if (pageType == '2') {
                //未到
                $("#weidaoToday").html(data[2].countNum);
                $("#weidaoYesterday").html(data[5].countNum);
                $("#weidaoMonth").html(data[8].countNum);
                $("#weidaoLastMonth").html(data[11].countNum);
            }
        }
    });
    ReservationsRecordTable.moneyAccount();
}

var Time = new Date();
var Year = Time.getFullYear();
var Month = Time.getMonth()+1;
var Day = Time.getDate();
if(Month < 10){
    Month = "0" + Month
}
if(Day < 10){
    Day = "0" + Day
}
var newDate = Year + "-" + Month + "-" + Day;  //今天
var newMonth = Year + "-" + Month;  //本月
Time.setDate(Time.getDate()-1);
var Year = Time.getFullYear();
var Month = Time.getMonth()+1;
var Day = Time.getDate();
var yestDate = Year + "-" + Month + "-" + Day;  //昨天
Time.setMonth(Time.getMonth() - 1);
var Month = Time.getMonth();
Month = ((Month==0)?(12):(Month));
var Year = Time.getFullYear();
var Month = Time.getMonth()+1;
var lastMonth =  Year + "-" + Month ; //上月

$(function () {
    $.post(Feng.ctxPath + "/payService/getList", function (data) {
        var txt = '<option value="">--请选择预约项目--</option>';
        for (var i = 0; i < data.length; i++) {
            txt += '<option value="' + data[i].department + '">' + data[i].department +
                '</option>';
        }
        document.getElementById('appointmentPayService').innerHTML = txt;
        //状态单选
        var seletepayservicename = $('#payservicenameValue').val();
        if (seletepayservicename != "") {
            $("#appointmentPayService option[value=" + seletepayservicename + "]").attr("selected", "selected");
        }
    }, "json");

    var pageType = $("#pageType").val();//空值表示是建档界面，0 未到界面  1已到界面
    if (pageType == '0') {
        //  建档 (默认结束建档时间)
        document.getElementById("startFilingTime").value = newDate + " " + "00:00:00";
        document.getElementById("endFilingTime").value = newDate + " " + "23:59:59";
    } else if (pageType == '1') {
        //  已到 (默认结束 首次到店时间)
        document.getElementById("startFirstVisitDate").value = newDate + " " + "00:00:00";
        document.getElementById("endFirstVisitDate").value = newDate + " " + "23:59:59";
    } else if (pageType == '2') {
        // 未到 (默认结束 首次到店时间)
        document.getElementById("startAppointmentTime").value = newDate + " " + "00:00:00";
        document.getElementById("endAppointmentTime").value = newDate + " " + "23:59:59";
    }

    //加载表格数据
    var defaultColunms = ReservationsRecordTable.initColumn();
    var table = new BSTable(ReservationsRecordTable.id, "/reservation/listYD",  //已到
        defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(ReservationsRecordTable.formParams());
    ReservationsRecordTable.table = table.init();
    //初始化统计数据
    ReservationsRecordTable.search();


    //初始化下拉项目列表
    $.post(Feng.ctxPath + "/payService/getList", function (data) {
        var txt = '<option value="">--请选择预约项目--</option>';
        for (var i = 0; i < data.length; i++) {
            txt += '<option value="' + data[i].department + '">' + data[i].department +
                '</option>';
        }
        document.getElementById('appointmentPayService').innerHTML = txt;
        //状态单选
        var seletepayservicename = $('#payservicenameValue').val();
        if (seletepayservicename != "") {
            $("#appointmentPayService option[value=" + seletepayservicename + "]").attr("selected", "selected");
        }
    }, "json");

    //初始化下拉到店门诊列表
    $.post(Feng.ctxPath + "/outpatientManagement/getList", function (data) {
        var txt = '<option value="">--请选择到店门诊--</option>';
        console.log(data);
        for (var i = 0; i < data.length; i++) {
            txt += '<option value="' + data[i].simplename + '">' + data[i].simplename + '</option>';
        }
        document.getElementById('arrivalStore').innerHTML = txt;
        //状态单选
        var seleteoarrivalStore = $('#arrivalStoreValue').val();
        if (seleteoarrivalStore != "") {
            $("#arrivalStore option[value=" + seleteoarrivalStore + "]").attr("selected", "selected");
        }
    }, "json");

    //采用定时器监听 时间内容是否变化
    var oldStartValue1 = $("#startFilingTime").val();
    var oldEndtimeValue1 = $("#endFilingTime").val();

    var oldStartValue2 = $("#startFirstVisitDate").val();
    var oldEndtimeValue2 = $("#endFirstVisitDate").val();

    var oldStartValue3 = $("#startAppointmentTime").val();
    var oldEndtimeValue3 = $("#endAppointmentTime").val();

    var oldArchivingValue = $("#archiving").val();

    var oldFollowerValue = $("#follower").val();
    var oldBelongerValue = $("#belonger").val();

    var oldOneChannelValue = $("#oneChannel").val();
    var oldTwoChannelValue = $("#twoChannel").val();
    var oldThrChannelValue = $("#thrChannel").val();
    setInterval(
        function () {//定时执行方法内容
            if ($("#startFilingTime").val() != oldStartValue1 || $("#endFilingTime").val() != oldEndtimeValue1) {//如果时间发生变化，就触发查询事件
                ReservationsRecordTable.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldStartValue1 = $("#startFilingTime").val();
                oldEndtimeValue1 = $("#endFilingTime").val();
            }
            if ($("#startFirstVisitDate").val() != oldStartValue2 || $("#endFirstVisitDate").val() != oldEndtimeValue2) {//如果时间发生变化，就触发查询事件
                ReservationsRecordTable.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldStartValue2 = $("#startFirstVisitDate").val();
                oldEndtimeValue2 = $("#endFirstVisitDate").val();
            }
            if ($("#startAppointmentTime").val() != oldStartValue3 || $("#endAppointmentTime").val() != oldEndtimeValue3) {//如果时间发生变化，就触发查询事件
                ReservationsRecordTable.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldStartValue3 = $("#startAppointmentTime").val();
                oldEndtimeValue3 = $("#endAppointmentTime").val();
            }
            if (oldArchivingValue != $("#archiving").val()) {
                ReservationsRecordTable.search();
                oldArchivingValue = $("#archiving").val();//每次判断为修改后把最新的文本框的值给原有变量，为下一次循坏执行方法体里面的判断做准备
            }
            if (oldBelongerValue != $("#belonger").val()) {
                ReservationsRecordTable.search();
                oldBelongerValue = $("#belonger").val();//每次判断为修改后把最新的文本框的值给原有变量，为下一次循坏执行方法体里面的判断做准备
            }
            if (oldFollowerValue != $("#follower").val()) {
                ReservationsRecordTable.search();
                oldFollowerValue = $("#follower").val();//每次判断为修改后把最新的文本框的值给原有变量，为下一次循坏执行方法体里面的判断做准备
            }
            if ($("#oneChannel").val() != oldOneChannelValue || $("#oneChannel").val() !=
                oldOneChannelValue) {//如果时间发生变化，就触发查询事件
                ReservationsRecordTable.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldOneChannelValue = $("#oneChannel").val();
            }
            if ($("#twoChannel").val() != oldTwoChannelValue || $("#twoChannel").val() !=
                oldTwoChannelValue) {//如果时间发生变化，就触发查询事件
                ReservationsRecordTable.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldTwoChannelValue = $("#twoChannel").val();
            }
            if ($("#thrChannel").val() != oldThrChannelValue || $("#thrChannel").val() !=
                oldThrChannelValue) {//如果时间发生变化，就触发查询事件
                ReservationsRecordTable.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldThrChannelValue = $("#thrChannel").val();
            }
        }, 500);

});
